home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c
- Subject: Implementation of 'strncmpi' function needed
- Date: 18 Apr 1996 07:13:05 GMT
- Organization: systems hk
- Message-ID: <4l4q21$qtv@nadine.teleport.com>
- NNTP-Posting-Host: ip-pdx07-11.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- Howdy,
-
- I have to use a quasi-C implementation that does not include
- a 'strncmpi' function, and therefore have created the following
- function to accomplish the task. However, I realize it is as
- inefficient in execution speed as it is efficient in trashing
- memory with numerous allocates/deallocates. I was wondering if
- anyone had suggestions for a more elegant/efficient solution,
- or has the 'strncmpi' C source I could plagarize (assembler is
- of no use, since the implementation does not allow for it).
- Thanks for your time.
-
- Yours, Geoff Houck
-
- /*-------------------------------------------------+
- strncmpi - case-insensitive 'strncmp' function
- +-------------------------------------------------*/
- int strncmpi ( char *astr, char *bstr, int len )
- {
- char *ta, *tb;
- int la, lb;
- int cmp;
-
- la = strlen( astr );
- lb = strlen( bstr );
-
- ta = malloc( la+1 );
- tb = malloc( lb+1 );
-
- strcpy( ta,astr );
- strcpy( tb,bstr );
-
- strupr( ta );
- strupr( tb );
-
- cmp = strncmp( ta,tb,len );
-
- free( ta );
- free( tb );
-
- return( cmp );
- }
-
-
-
-